package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook 地址簿实体类
     */
    void intert(AddressBook addressBook);

    /**
     * 查询当前登录用户的所有地址信息
     * @param addressBook 地址簿实体类
     * @return AddressBook集合
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 根据id修改地址
     * @param addressBook 地址簿实体类
     */
    void update(AddressBook addressBook);

    /**
     * 根据id删除地址
     * @param id 地址id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteByid(Long id);

    /**
     * 设置默认地址
     * @param addressBook 地址簿实体类
     */
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateByDefault(AddressBook addressBook);

    /**
     * 根据id查询地址
     * @param addressBookId 地址id
     * @return AddressBook
     */
    @Select("select * from address_book where id = #{Id}")
    AddressBook getByid(Long id);
}
